package org.gd.hellojaxb.adapters;

import javax.xml.bind.annotation.adapters.XmlAdapter;


public class BooleanAdaptersFactory {

    public static String getFormattedAmount(Double amount) {
        return String.format("%.2f", amount);
    }

    public static final class Integer extends XmlAdapter<String, Boolean> {
        @Override
        public Boolean unmarshal(String v) throws Exception {
            if(v == null) {
                return null;
            }
            return java.lang.Integer.parseInt(v) > 0;
        }
        @Override
        public String marshal(Boolean v) throws Exception {
            if(v == null) {
                return null;
            }
            return v ? "1" : "0";
        }
    }
}
